package mil.af.amc.adpetracker.web.actions.struts1.AdpeAccount;

import mil.af.amc.adpetracker.web.actions.struts1.AbstractAction;
import mil.af.amc.adpetracker.service.AdpeAccountService;
import mil.af.amc.adpetracker.service.ServiceException;
import mil.af.amc.adpetracker.exceptions.IllegalUnassignmentOfPrimaryCustodianException;
import org.apache.struts.action.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Please fill in this Javadoc
 *
 * @author TSgt Ferguson
 */
public class AssignAlternateCustodianAction extends AbstractAction {

    private AdpeAccountService adpeAccountService;

    public void setAdpeAccountService(AdpeAccountService adpeAccountService) {
        this.adpeAccountService = adpeAccountService;
    }

    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        DynaActionForm form = (DynaActionForm) actionForm;

        try {
            adpeAccountService.assignAlternateCustodian(form.getMap());
        } catch (ServiceException e) {

            ActionMessage message = new ActionMessage(e.getKey());
            saveError(httpServletRequest, message);

        } catch (IllegalUnassignmentOfPrimaryCustodianException e) {

        }

        return actionMapping.findForward("success");

    }
}
